package com.smartwasser.yunhtgl.apphtgl.presenter;

import com.smartwasser.yunhtgl.apphtgl.bean.SP1Bean;
import com.smartwasser.yunhtgl.apphtgl.network.RetrofitApi;
import com.smartwasser.yunhtgl.apphtgl.network.Retrofits;
import com.smartwasser.yunhtgl.apphtgl.view.SP01View;
import com.smartwasser.yunhtgl.apphtgl.utils.Logger;

import rx.Observer;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

public class SP01PresenterImpl implements SP01Presenter {
    private SP01View sp01View;

    public SP01PresenterImpl(SP01View sp0001View) {
        this.sp01View = sp0001View;
    }

    @Override
    public void getType1SP01(String JSESSIONID, int pageNo, String category, String procurementMode) {
        Retrofits.getInstance().createReq(RetrofitApi.class).getType1Sp102(JSESSIONID, pageNo, category, procurementMode, "1", 10)
                .subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<SP1Bean>() {
            @Override
            public void onCompleted() {
            }

            @Override
            public void onError(Throwable e) {
                sp01View.error();
            }

            @Override
            public void onNext(final SP1Bean spBean) {
                sp01View.success(spBean);
            }
        });
    }

    @Override
    public void getType1SP02(String JSESSIONID, int pageNo, String category, String procurementMode) {
        Retrofits.getInstance().createReq(RetrofitApi.class).getType1Sp102(JSESSIONID, pageNo, category, procurementMode, "0", 10)
                .subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<SP1Bean>() {
            @Override
            public void onCompleted() {
            }

            @Override
            public void onError(Throwable e) {
                sp01View.error();
                Logger.e("onError");
            }

            @Override
            public void onNext(final SP1Bean spBean) {
                sp01View.success(spBean);
            }
        });
    }

    @Override
    public void getType1SP04(String JSESSIONID, int pageNo, String category, String procurementMode, String moneyRange) {
        Retrofits.getInstance().createReq(RetrofitApi.class).getType1Sp3(JSESSIONID, pageNo, category, procurementMode, moneyRange, 10)
                .subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<SP1Bean>() {
            @Override
            public void onCompleted() {
            }

            @Override
            public void onError(Throwable e) {
                sp01View.error();
            }

            @Override
            public void onNext(final SP1Bean spBean) {
                sp01View.success(spBean);
            }
        });
    }
}